<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改项目</title>
    <link rel="stylesheet" th:href="@{/component/pear/css/pear.css}" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">项目名称</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="id" th:value="${project.id}" lay-verify="title" autocomplete="off"  class="layui-input">
                        <input type="text" name="projectName"  th:value="${project.projectName}" lay-verify="title" autocomplete="off"    placeholder="请输入项目名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">项目说明</label>
                    <div class="layui-input-block">
                        <input type="text"  name="projectDescription" th:value="${project.projectDescription}"  lay-verify="title" autocomplete="off"    placeholder="请输入项目说明" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">项目联系人</label>
                    <div class="layui-input-block">
                        <input type="text"  name="projectContact" th:value="${project.projectContact}" lay-verify="title" autocomplete="off"    placeholder="请输入项目联系人" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">项目是否完成</label>
                    <div class="layui-input-block" th:if="${project.completeFlag == '1'}">
                        <input type="radio" name="completeFlag" value="0" title="未完成">
                        <input type="radio" name="completeFlag" value="1" title="已完成" checked>
                    </div>
                    <div class="layui-input-block" th:if="${project.completeFlag == '0'}">
                        <input type="radio" name="completeFlag" value="0" title="未完成" checked>
                        <input type="radio" name="completeFlag" value="1" title="已完成">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">项目完成时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="completionTime" id="date" th:value="${#dates.format(project.completionTime, 'yyyy-MM-dd')}"  lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">项目备注</label>
                    <div class="layui-input-block">
                        <input type="text"  name="projectRemark" th:value="${project.projectRemark}"  lay-verify="title" autocomplete="off" placeholder="请输入项目备注" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">远程连接方式</label>
                    <div class="layui-input-block">
                        <input type="text"  name="remoteConnectionMode" th:value="${project.remoteConnectionMode}"  lay-verify="title" autocomplete="off"   placeholder="请输入远程连接方式" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">远程连接地址</label>
                    <div class="layui-input-block">
                        <input type="text"  name="remoteConnectionAddress" th:value="${project.remoteConnectionAddress}"  lay-verify="title" autocomplete="off" placeholder="请输入远程连接地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">远程连接密码</label>
                    <div class="layui-input-block">
                        <input type="text"  name="remoteConnectionPassword"  th:value="${project.remoteConnectionPassword}"  lay-verify="title" autocomplete="off" placeholder="请输入远程连接密码" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">客户名称</label>
                    <div class="layui-input-block">
                        <select name="customerId" id="customerId" lay-verify="title" lay-filter="customer-query" >
                            <option value=""></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="project-edit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script th:src="@{/component/layui/layui.js}"></script>
<script th:src="@{/component/pear/pear.js}"></script>
<script th:inline="javascript">
layui.use(['form','jquery','laydate'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    let laydate = layui.laydate;

    //日期
    laydate.render({
        elem: '#date'
    });

    $.ajax({
        url: '/api/customer/listCustomerName',
        dataType: 'json', //服务器返回json格式数据
        type: 'get', //HTTP请求类型
        timeout: 10000, //超时时间设置为10秒；
        success: function(data) {
            $.each(data.data, function (index, value) {
                $('#customerId').append(new Option(value.customerName,value.id));// 下拉菜单里添加元素
            });

            // 工具客户id，选择客户对应的值
            const value = [[${project.customerId}]];
            $('#customerId').find("option[value="+value+"]").attr("selected",true);
            layui.form.render("select");
        }
    });




    form.on('submit(project-edit)', function(data){
        $.ajax({
            url:'/api/project/update',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code == "1000"){
                    layer.msg(result.message,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("project-table");
                    });
                }else{
                    layer.msg(result.message,{icon:2,time:1000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>
